$(function() {
	
	//申明几个选择的值
	var price = price1 = price2 = price3 = price4 = price5 = str = 0;
	//初始化图表
	showChart(0);

	//初始化贷款额度
	$('.loan-price').text(price);

})
//选择身份特征
$('.ident-select').on('change', function() {

	var str1 = price1 + price4 + str + price5;
	if($('.ident-select').val() == '公务员') {
		price = str1 + 1;
		showChart(price);
		$('.loan-price').text(price);
	} else if($('.ident-select').val() == '自由职业') {
		price = str1 + 0.5;
		$('.loan-price').text(price);
		showChart(price);
	} else if($('.ident-select').val() == '企业主') {
		price = str1 + 10;
		$('.loan-price').text(price);
		showChart(price);
	} else if($('.ident-select').val() == '个体户') {
		price = str1 + 1;
		$('.loan-price').text(price);
		showChart(price);
	} else if($('.ident-select').val() == '上班族') {
		price = str1 + 5;
		$('.loan-price').text(price);
		showChart(price);
	}
	price2 = price

});
//选择月收入
$('.ident-select1').on('change', function() {

	var str2 = price1 + price2 + price4 + price5;

	if($('.ident-select1').val() == '低于2000') {
		str = 0.5;
		price = str2 + str;
		$('.loan-price').text(price);
		showChart(price);
	} else if($('.ident-select1').val() == '2000~3000') {
		str = 0.8;
		price = str2 + str;
		$('.loan-price').text(price);
		showChart(price);
	} else if($('.ident-select1').val() == '3000~6000') {
		str = 1.5;
		price = str2 + str;
		$('.loan-price').text(price);
		showChart(price);

	} else if($('.ident-select1').val() == '6000~9000') {
		str = 2;
		price = str2 + str;
		$('.loan-price').text(price);
		showChart(price);
	} else if($('.ident-select1').val() == '9000~12000') {
		str = 4;
		price = str2 + str;
		$('.loan-price').text(price);
		showChart(price);
	} else if($('.ident-select1').val() == '12000以上') {
		str = 6;

		price = str2 + str;
		$('.loan-price').text(price);
		showChart(price);
	}
	price3 = price

});
//选择房产
$('.house input[type=radio]').on('click', function() {
	var str3 = price3 + price4 + price5;
	if($('.house input[type=radio]:checked').val() == '有') {
		price1 = 10;
		price = str3 + price1;
		$('.loan-price').text(price);
		showChart(price);
	} else {
		price1 = 0;
		price = str3 + price1;
		$('.loan-price').text(price);
		showChart(price);
	}
});
//选择车产
$('.car input[type=radio]').on('click', function() {
	var str4 = price3 + price1 + price5;
	if($('.car input[type=radio]:checked').val() == '有') {
		price4 = 5;

		price = str4 + price4;
		$('.loan-price').text(price);
		showChart(price);
	} else {
		price4 = 0;
		price = str4 + price4;
		$('.loan-price').text(price);
		showChart(price);
	}
});
//选择公积金
$('.gong input[type=radio]').on('click', function() {

	var str5 = price3 + price1 + price4;
	console.log(price3, price1, price4)
	if($('.gong input[type=radio]:checked').val() == '有') {
		price5 = 10;

		price = str5 + price5;
		$('.loan-price').text(price);
		showChart(price);
	} else {
		price5 = 0;
		//		console.log(str5)
		price = str5 + price5;
		$('.loan-price').text(price);
		showChart(price);
	}
});
//展示图表
function showChart(price) {

	var num = price;
	var myChart = echarts.init(document.getElementById('main'));

	option = {
		backgroundColor: 'transparent',

		series: [{
				type: 'gauge',
				radius: '85%',
				startAngle: '190',
				endAngle: '-10',
				splitNumber: 32,
				detail: {
					offsetCenter: [0, -50],
					formatter: ' '
				},
				pointer: {
					show: false
				},
				axisLine: {
					show: true,
					lineStyle: {
						color: [
							[0, '#7691FA'],
							[num / 40, `red`],
							[1, '#e9e9e9']
						],
						width: 35
					}
				},
				axisTick: {
					show: false
				},
				splitLine: {
					show: true,
					length: 35,
					lineStyle: {
						color: '#fff',
						width: 6
					}
				},
				axisLabel: {
					show: false
				}
			}

		]
	};
	myChart.setOption(option);
}

function onChange() {
	$('.ident-select').val() != '请选择' ? $('.identi-img').attr("src", "images/index-icon1.png") : $('.identi-img').attr("src", "images/index-icon.png");
	$('.ident-select1').val() != '请选择' ? $('.identi-img1').attr("src", "images/index-icon1.png") : $('.identi-img1').attr("src", "images/index-icon.png");
}

function onChangeHouse(img) {
	img.attr("src", "images/index-icon1.png");
}
//下一步判断
$('.index-sure').on('click', function() {

	if($('.ident-select').val() == '请选择') {
		layer.msg('请选择身份特征！');
	} else {
		if($('.ident-select1').val() == '请选择') {
			layer.msg('请选择月收入！');
		} else {

			if($('.horse-img').attr('src') == 'images/index-icon.png') {
				layer.msg('请选择有无房产！');
			} else {
				if($('.car-img').attr('src') == 'images/index-icon.png') {
					layer.msg('请选择有车产！');
				} else {
					if($('.gong-img').attr('src') == 'images/index-icon.png') {
						layer.msg('请选择有无公积金！');
					} else {

						window.location.href = "loantable.html";
					}
				}
			}

		}
	}
})